#coding=utf-8
#__author__ = 'bing.cheng'

from BeautifulSoup import BeautifulSoup
import  requests
import threading
import re
import  chardet

# iplist=["183.57.77"]

class Scanweb:
    def __init__(self,ipc):
        self.ipcfile = ipc
        self.ipc=[]

    def scan(self):
            file=open("result.txt","a")
            self.loadip()
            for i in self.ipc:
                for c in range(1,255):
                    full_url="http://"+i+"."+str(c)
                    print full_url
                    try:
                        r=requests.get(full_url,timeout=1)
                        codestyle=r.encoding
                        soup=BeautifulSoup(r.text.encode(codestyle))
                        abc=soup.title
                        t="[+] <[%s]> %s %s" % (r.status_code, full_url,abc)
                        file.write(t+"\n")

                    except Exception as e:
                        print "time out: "+ str(e)
            file.close()


    def loadip(self):
        file=open(self.ipcfile)
        for i in file.readlines():
             self.ipc.append(i.strip())
             file.close()
        print self.ipc

if __name__=="__main__":
    S=Scanweb(ipc="ip.txt")
    t=threading.Thread(target=S.scan(),)
    t.setDaemon(True)
    t.start()
    t.join()
    S.scan()